package com.lingnan.blog.mapper;

import com.lingnan.blog.entity.Collect;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * @author HeGuanChao
 */
@Mapper
public interface CollectMapper {
    int deleteByPrimaryKey(Integer id);

    int insert(Collect record);

    int insertSelective(Collect record);

    Collect selectByPrimaryKey(Integer id);

    int updateByPrimaryKeySelective(Collect record);

    int updateByPrimaryKey(Collect record);

    /**
     * 根据用户id和文章id查询收藏记录
     *
     * @param uid
     * @param aid
     * @return
     */
    @Select("select * from collect where u_id = #{uid} and a_id = #{aid} ")
    Collect selectByUidAndAid(@Param("uid") Integer uid, @Param("aid") Integer aid);

    /**
     * 根据当前用户id和文章id删除收藏记录
     *
     * @param uid
     * @param aid
     * @return
     */
    @Delete("delete from collect where u_id = #{uid} and a_id = #{aid} ")
    Integer deleteByUidAndAid(@Param("uid") Integer uid, @Param("aid") Integer aid);

    /**
     * 根据用户id查询用户的收藏总数量
     * @param uid
     * @return
     */
    @Select("select count(*) from collect where u_id = #{uid} ")
    Integer countByUId(Integer uid);
}